import axios from "axios";
import GLOBAL from './Global.vue';
/**
 * 
 * @param {*} that  -- 调用该方法的页面
 * @param {*} url -- 服务器url
 * @param {*} params  -- 发送的信息
 * @param {*} event -- 获取数据成功后调用的方法
 * @param {*} errorEvent  -- 获取数据失败后调用的方法
 */
function httpPost(that, url, params, event, errorEvent) {
   
    axios
        .post(GLOBAL.BASE_URL + url, params)
        .then((response) => {
            var data = response.data;
            console.log(data)
            if (data.result == "SUCCESS") {
                // that.$message({
                //     message: data.detail,
                //     type: 'success'
                // });
            }else if(data.result == undefined){
                that.$message({
                    message: data.detail,
                    type: 'error'
                });
            }else {
                that.$message({
                    message: data.detail,
                    type: 'warning'
                });
            }
            event(data);
        })
        .catch(function (error) {
            that.$message({
                message: error,
                type: 'error'
            });
            errorEvent(error);
        });
}
export default {
    httpPost
}
